package app.server.project.main.service.controller;

import app.server.project.core.constants.Def;
import app.server.project.core.http.RespModel;
import app.server.project.main.service.db.entity.RoomEntity;
import app.server.project.main.service.dto.room.RoomInfoDto;
import app.server.project.main.service.service.RoomService;
import cn.hutool.core.util.IdUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房间管理
 */
@AllArgsConstructor
@RequestMapping("/room")
@RestController
public class RoomController {

    private RoomService roomService;

    /**
     * 拉取房间列表
     * @param userId
     * @return
     */
    @GetMapping("/getRoomsByUserId")
    public RespModel getRoomsByUserId(@RequestHeader(Def.UserId)long userId){
        return RespModel.success(this.roomService.getRoomsByUserId(userId));
    }

    /**
     * 删除房间
     * @param userId
     * @param roomId
     */
    @PostMapping("/delRoom/{roomId}")
    public RespModel delRoom(@RequestHeader(Def.UserId)long userId,@PathVariable long roomId){
      return   RespModel.success(this.roomService.delRoom(userId, roomId));
    }

    /**
     * 添加房间
     * @param userId
     * @param dto
     * @return
     */
    @PostMapping("/addRoom")
    public RespModel addRoom(@RequestHeader(Def.UserId)long userId,@RequestBody RoomInfoDto dto){
        this.roomService.addRoom(userId, dto);
        return RespModel.success();
    }

    /**
     * 修改房间名称
     * @param userId
     * @param
     *
     */
    @PostMapping("/updateName")
    public RespModel updateName(@RequestHeader(Def.UserId)long userId,@RequestBody RoomInfoDto dto){
        this.roomService.updateName(userId, dto);
        return RespModel.success();
    }
}
